package org.eenie.core.base.viewmodel

import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import androidx.viewbinding.ViewBinding
import com.blankj.utilcode.util.LogUtils
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import org.eenie.core.base.viewbinding.BaseBindingActivity

abstract class BaseBindingViewModelActivity<BD : ViewBinding, VS : Any, VM : BaseViewModel<VS>> : BaseBindingActivity<BD>() {

    lateinit var viewModel: VM

    override fun onCreate(savedInstanceState: Bundle?) {
        viewModel = providerViewModel()
        super.onCreate(savedInstanceState)
        viewModel.state.onEach {
            renderUI(it)
        }.launchIn(lifecycleScope)
    }


    abstract fun providerViewModel(): VM
    abstract fun renderUI(state: VS)
}